package com.king.modules.system.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.king.common.annotation.MvcData;
import com.king.common.constant.Constants;
import com.king.common.exception.AssertHelper;
import com.king.common.utils.SecurityUtils;
import com.king.framework.base.controller.YyTreeController;
import com.king.framework.base.domain.vo.AjaxResult;
import com.king.framework.base.domain.vo.PageResult;
import com.king.modules.system.domain.SysOrgEntity;
import com.king.modules.system.service.SysOrgService;

@RestController
@RequestMapping(value = "/system/org")
public class SysOrgController extends YyTreeController<SysOrgEntity>{
	
	@SuppressWarnings("unused")
	@Autowired
	private SysOrgService sysOrgService;

	
    @MvcData("查询")
    @PreAuthorize("@sps.hasAuthority('system:org:groupQuery')")
    @PostMapping(value = "/groupQuery")
    public AjaxResult groupQuery(HttpServletRequest request, @RequestBody(required = false) Map<String, Object> searchMap) throws Exception {
		AssertHelper.getInstance().checkException(!SecurityUtils.isAdmin(), "没有权限");
        if (searchMap == null) {
            searchMap = new HashMap<String, Object>();
        }
        searchMap.putAll(addSearchParam(request));
//        searchMap.put("EQ_parentid", Constants.TREE_ORG_ROOTID);
        searchMap.put("IN_parentid", Constants.TREE_ORG_ROOTID+",0");
        dealSearch(request, searchMap);

        PageResult<SysOrgEntity> datas = baseService.doQuery(searchMap);
        return success(datas);
    }
}
